<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let salaries = {
        John: 100,
        Ann: 160,
        Pete: 130,
      };

      // 统计属性个数
      function length(obj) {
        let n = 0; //记录循环的次数
        for (let k in obj) {
          n++;
        }
        return n;
      }

      // 计算累加和
      function sum(obj) {
        let r = 0;
        for (let k in obj) {
          r = r + obj[k];
        }
        return r;
      }

      // 计算平均值
      function avg(obj) {
        return sum(obj) / length(obj);
      }

      console.log(avg(salaries));
      // console.log(sum(salaries));
      // console.log(length(salaries));
    </script>
  </body>
</html>
